package com.young.storage.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.young.storage.entity.Storage;
import com.young.storage.mapper.StorageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("storage")
public class StorageController {
    @Autowired
    private StorageMapper storageMapper;

    @RequestMapping("create")
    public void insert(@RequestBody Storage storage){
        storageMapper.insert(storage);
    }

    @RequestMapping("reduce/{goodId}")
    public void reduceStorage(@PathVariable("goodId") Integer goodId){
        Storage storage = storageMapper.selectOne(new QueryWrapper<Storage>().eq("good_id", goodId));
        storage.setStoreNum(storage.getStoreNum()-1);
        storageMapper.updateById(storage);
    }
}
